class StorehousesController < ApplicationController
  
  def index
    params[:key_word] = "%#{params[:key_words]}%"
    @storehouses = Dept::Storehouse.where('name like :key_word or address like :key_word or link_man like :key_word or link_phone like :key_word ',params).order('created_at asc')
  end
  
  def new 
    @storehouse = Dept::Storehouse.new
  end
  
  def create
    @storehouse = Dept::Storehouse.new(params[:dept_storehouse])
    if @storehouse.save
      redirect_to :action => :index
    else
      render :new
    end
  end
  
  def edit
    @storehouse = Dept::Storehouse.find(params[:id])
  end
  
  def update
    @storehouse = Dept::Storehouse.find(params[:id])
    if @storehouse.update_attributes(params[:dept_storehouse])
      redirect_to :action => :index
    else
      render :edit
    end
  end
  
  def hide
    @storehouse = Dept::Storehouse.find(params[:id])
    @storehouse.hidden!
    redirect_to :action => :index
  end

  def visible
    @storehouse = Dept::Storehouse.find(params[:id])
    @storehouse.visible!
    redirect_to :action => :index
  end
end
